<?php
namespace app\manage\controller;

use think\Request;

/**
* 菜单管理
* @author xuyunlong <416319808@qq.com>
*/
class Menu extends Common
{
	private $menu;

	public function _initialize()
    {
        $this->menu = model('menu');
    }

	public function index()
	{
		return view('_index');
	}


	/**
	 * 菜单添加编辑
	 */
	public function add()
	{
		if (Request::instance()->isPost()) {
			$data = input('post.');
			if (!$data['id']) {
				unset($data['id']);
			}

			$validate = validate('Menu');
			if($validate->scene('add')->check($data)){
				if (!$this->menu->data($data)->save()) {
					return json(['status' => 0, 'info' => '保存失败']);
				} else {
					return json(['status' => $this->menu->id, 'info' => '保存成功']);
				}
			} else {
				return json(['status' => 0, 'info' => $validate->getError()]);
			}

		} else {
			return view('',['title'=>'菜单管理']);
		}
	}


	public function parentNode()
	{
		$data = $this->menu->node();
		exit(json_encode($data));
	}



}
